﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace WellDone
{
    public sealed partial class KeyPadControl : UserControl
    {
        //Button Text Property
        public string ClickedButtonValue;

        //Numeric KeyPad Mode Property
        public Mode KeyPadMode { get; set; }

        //Enum for Standard or Calculator mode
        public enum Mode
        {
            Standard,
            Calculator
        }

        public event RoutedEventHandler ButtonClick;

        public KeyPadControl()
        {
            this.InitializeComponent();
        }

        private void KeyPadControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (KeyPadMode == Mode.Standard)
            {
                btn1.Margin = new Thickness(3, 3, 0, 0);
                btn2.Margin = new Thickness(86, 3, 0, 0);
                btn3.Margin = new Thickness(169, 3, 0, 0);
                btn4.Margin = new Thickness(3, 56, 0, 0);
                btn5.Margin = new Thickness(85, 56, 0, 0);
                btn6.Margin = new Thickness(169, 57, 0, 0);
                btn7.Margin = new Thickness(3, 110, 0, 0);
                btn8.Margin = new Thickness(86, 111, 0, 0);
                btn9.Margin = new Thickness(169, 111, 0, 0);
            }
            else if (KeyPadMode == Mode.Calculator)
            {
                btn1.Margin = new Thickness(3, 110, 0, 0);
                btn2.Margin = new Thickness(86, 111, 0, 0);
                btn3.Margin = new Thickness(169, 111, 0, 0);
                btn4.Margin = new Thickness(3, 56, 0, 0);
                btn5.Margin = new Thickness(85, 56, 0, 0);
                btn6.Margin = new Thickness(169, 57, 0, 0);
                btn7.Margin = new Thickness(3, 3, 0, 0);
                btn8.Margin = new Thickness(86, 3, 0, 0);
                btn9.Margin = new Thickness(169, 3, 0, 0);
            }
        }

        private void btnClick(object sender, RoutedEventArgs e)
        {
            try { 
                Button btn = (Button)sender;
                ClickedButtonValue = Convert.ToString(btn.Content);
            }
            catch { }            
            ButtonClick(sender, e);
        }        

    }
}
